/*=====================================================================================================================
                    Copyright(c) 2009 Geometric PLM Software Corp. All rights reserved.
                             Unpublished - All rights reserved
=======================================================================================================================
File description:
    Filename: tc_bom.c
    Module  : (geometric) itk module.

        This file manages the operations of the bom.

=======================================================================================================================
Date               Name              Description of Change
14-Jul-2009        Jerry,Wu          Initialize creation
$HISTORY$
====================================================================================================================*/
#ifndef _cplusplus
#define _CRT_SECURE_NO_DEPRECATE
#endif

#ifdef BUILD_IMAN 
#include <iman_string.h>
#define  GTC_strcpy                     iman_strcpy

#else // Teamcenter
#include <fclasses\tc_string.h>
#define  GTC_strcpy                     tc_strcpy

#endif

#include <ai\sample_err.h>
#include <bom\bom.h>
#include <stdlib.h>
#include <tccore\aom.h>

#include "tc_bom.h"


int GBOM_get_attr_display_value( tag_t bomlineTag, const char *propName, char **value)
{
    int attribute = 0, mode = 0;

    *value = NULL;

    CALL(BOM_line_look_up_attribute(propName, &attribute));
    CALL(BOM_line_ask_attribute_mode(attribute, &mode));
    switch(mode)
    {
    case BOM_attribute_mode_string:
    case BOM_attribute_mode_string_intl:
        {
            CALL(BOM_line_ask_attribute_string(bomlineTag, attribute, value));
        }
        break;
    case BOM_attribute_mode_logical:
        {
            logical lValue = false;
            CALL(BOM_line_ask_attribute_logical(bomlineTag, attribute, &lValue));
            *value = MEM_alloc(2);
            memset(*value, 0, 2);
            GTC_strcpy(*value, lValue ? "Y" : "N");
        }
        break;
    case BOM_attribute_mode_int:
        {
            int nValue = 0;
            CALL(BOM_line_ask_attribute_int(bomlineTag, attribute, &nValue));
            *value = MEM_alloc(32);
            memset(*value, 0, 32);
            sprintf(*value, "%d", nValue);
        }
        break;
    case BOM_attribute_mode_tag:
        {
            tag_t objTag = NULL_TAG;
            CALL(BOM_line_ask_attribute_tag(bomlineTag, attribute, &objTag));
            CALL(AOM_ask_name(objTag, value));
        }
        break;
    case BOM_attribute_mode_double:
        {
            double dbValue = 0;
            CALL(BOM_line_ask_attribute_double(bomlineTag, attribute, &dbValue));
            *value = MEM_alloc(64);
            memset(*value, 0, 64);
            sprintf(*value, "%f", dbValue);
        }
        break;
    }
    return ITK_ok;
}
